package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.RoomRequestVO;
import com.yugong.entity.vo.response.RoomListResponseVO;
import com.yugong.service.RoomService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房间控制器类
 *
 * @author yugong
 * @date 2024/2/25
 */
@RestController
@RequestMapping("/api/room")
public class RoomController {
    @Resource
    private RoomService roomService;

    /**
     * 根据房间名查询房间
     *
     * @param pageNum  当前页
     * @param pageSize 当前页的数据个数
     * @param roomName 房间名
     * @return 房间
     */
    @GetMapping("/find-room-page")
    public Result findRoomPage(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               @RequestParam String roomName) {
        PageInfo<RoomListResponseVO> roomListResponseVOPageInfo = roomService.findRoom(pageNum, pageSize, roomName);
        return Result.success(roomListResponseVOPageInfo);
    }

    /**
     * 新增房间
     *
     * @param roomRequestVO 房间请求实体类
     * @return 响应码
     */
    @PostMapping("/add-room")
    public Result addRoom(@RequestBody RoomRequestVO roomRequestVO) {
        int addFlag = roomService.addRoom(roomRequestVO);
        return Result.success(addFlag);
    }

    /**
     * 更新房间
     *
     * @param roomRequestVO 房间请求实体类
     * @return 响应码
     */
    @PutMapping("/update-room")
    public Result updateRoom(@RequestBody RoomRequestVO roomRequestVO) {
        int updateFlag = roomService.updateRoom(roomRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除房间
     *
     * @param roomNo 房号
     * @return 响应码
     */
    @DeleteMapping("/delete-room/{roomNo}")
    public Result deleteRoom(@PathVariable String roomNo) {
        int deleteFlag = roomService.deleteRoom(roomNo);
        return Result.success(deleteFlag);
    }

    /**
     * 查询房间
     *
     * @return 房间
     */
    @GetMapping("/find-room")
    public Result findRoom() {
        List<RoomRequestVO> roomRequestVOList = roomService.findRoom();
        return Result.success(roomRequestVOList);
    }
}
